package com.swpu.zdl.controller;

import com.swpu.zdl.pojo.KeCheng;
import com.swpu.zdl.service.KeChengService;
import com.swpu.zdl.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/kecheng")
public class KeChengController {
    @Autowired
    private KeChengService keChengService;

    // 获取全部课程信息
    @GetMapping("/getAll")
    public Result getAll() {
        List<KeCheng> keChengs = keChengService.getAll();
        return new Result(200, "所有课程信息", keChengs);
    }

    // 插入新的课程
    @PostMapping("/addKeCheng")
    public Result addKeCheng(@RequestBody KeCheng keCheng) {
        Boolean b = keChengService.addKeCheng(keCheng);
        if (!b) return new Result(500, "添加课程失败");
        return new Result(200, "添加课程成功");
    }

    // 删除课程
    @DeleteMapping("/deleteKeCheng/{kno}")
    public Result deleteKeCheng(@PathVariable Integer kno) {
        if (!keChengService.deleteKeCheng(kno)) return new Result(500, "删除失败");
        return new Result(200, "删除课程成功");
    }

    // 修改课程
    @PutMapping("/updateKeCheng/{kno}")
    public Result updateKeCheng(@PathVariable Integer kno, @RequestBody KeCheng keCheng) {
        if (!keChengService.updateKeCheng(kno, keCheng)) return new Result(500, "修改课程失败");
        return new Result(200, "修改课程成功");
    }
    // 查看当前课程的老师
    @GetMapping("/getCouresTeacher")
    public Result getCouresTeacher(String kno){
        KeCheng keCheng = keChengService.getCoureseTeacher(kno);
        return new Result(200, "查看当前课程的老师", keCheng);
    }
}
